package com.ccbhelper.tranflows;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import org.json.simple.JSONObject;

//client send request to the Server using Socket 
public class JsonReq {

	public static Map sendRequest(String[][] property,String className,String methodName){
		
		JSONObject propJson  = new JSONObject();
		for (int len = 0; len <= property.length-1; len++)
			propJson.put(property[len][0], property[len][1]);
		JSONObject reqJson  = new JSONObject();
		reqJson.put("property", propJson);
		reqJson.put("className", className);
		reqJson.put("methodName", methodName);
		
		String resp;
		Object jsonObj=null;
		Map respResult=new HashMap();
		Map result=new HashMap();
		ArrayList<Map> resultList=new ArrayList<Map>();
		try {
			resp = SocketClient.SendRequest(reqJson.toJSONString());
			System.out.println(resp);
			jsonObj=JSONTool.convertJsonToObject(resp);
			respResult=(HashMap)jsonObj;
			String mes=respResult.get("code").toString();
			result=(HashMap)respResult.get(methodName);			
			for(int i=0;i<result.values().size();i++)
			{
				System.out.println(result.values().toArray()[i].toString());
				resultList.add((Map)result.values().toArray()[i]);
			}
			System.out.println(resultList.get(0).get("phone"));
		} catch (Throwable e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}		
		return respResult;		
	}

}
